package com.zbystudy.reflect;

import com.zbystudy.po.Dog;
import org.apache.commons.lang3.StringUtils;

/**
 * Created By zby on 18:00 2019/3/16
 * 加载当前类信息
 */

public class LoadCurrentClass {

    /**
     * Created By zby on 18:07 2019/3/16
     * 通过上下文的类路径来加载信息
     */
    public static Class byClassPath(String classPath) {
        if (StringUtils.isBlank(classPath)) {
            throw new RuntimeException("类路径不能为空");
        }
        classPath = classPath.replace(" ", "");
        try {
            return Class.forName(classPath);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * Created By zby on 18:16 2019/3/16
     * 通过类字面常量加载当前类的信息
     */
    public static void byClassConstant() {
        System.out.println(Dog.class);
    }

   /**
    * Created By zby on 18:17 2019/3/16
    * 通过类对象加载当前类的信息
    */
    public static Class byCurrentObject(Object object) {
        return object.getClass();
    }
}
